Repository navigation
feat(attachments): attachments go where the workspace lives (whole attachments plan; SUPER-3014, SUPER-2658, SUPER-2874) - #9064
Conversation
…-service bodies (SUPER-2658) Pasting or dropping an image into a cloud workspace failed with "Failed to send the file to the remote workspace" (terminal) or "Couldn't attach files / value$1 is not iterable" (chat). The desktop was shipping the bytes as a base64 `filesystem.writeFile` body over the streaming tRPC link. tRPC answers a streamed batch before it has read the request body, and a Vercel sandbox's ingress treats that early response as the end of the exchange and drops the upload still in flight — a race, not a size limit: a 500 KB body on a home uplink loses it about half the time. Desktop: the chat composer, the terminal rich input, and the terminal paste/drop override now take the route every other composer already takes (mobile, the new-workspace modal): `attachment.createUpload`, a presigned PUT to storage, `cloudWorkspace.attachFiles` for a box, then `attachments.materializeIntoWorkspace` on the host. The host-service request carries ids, never bytes. `uploadPastedFiles` is replaced by `sendAttachmentsToWorkspace` + `useSendAttachments`. host-service: `/trpc/*` buffers the request body before handing it to tRPC so no response can start before the request is complete; the integration test fails without it. `materializeIntoWorkspace` and the chat image writer share one helper that creates `.superset/attachments` with its `.gitignore`, which the former never wrote.
…ap files with the box
First API step of the attachment plan (SUPER-2874, seam 6).
- attachment.resolve no longer signs a URL for any composer upload in the
org. A kept (ready) file resolves only through a cloud workspace the
caller can see. An upload still in flight (pending) stays org-wide: a
host resolves with its owner's credential, and the sender can be a
teammate on that host. A box still sees only its own workspace's files.
- New attachment.resolveEach returns one entry per id, with
{ fileId, missing: true } for a file that is gone or not visible, so a
transcript can render the rest. resolve keeps its output and errors for
released hosts.
- The archive's final reap stage (and the fallback when it cannot be
queued) detaches and deletes the files anchored to the workspace.
…upload limits The chat composer always shipped attachments as base64 through filesystem.writeFile, with the 50MB/200MB caps meant for remote workspaces. In a local workspace a disk-backed file is now copied into .superset/attachments by the Electron main process, so no size cap applies and the bytes never pass through renderer memory. Clipboard blobs and remote workspaces keep the upload path and its limits. Fixes SUPER-3014
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Merge Risk:
|
[Medium impact] The change reaches chat attachment handling in desktop workspaces. The PR appears safe to merge, with a non-blocking improvement needed to make the copy route’s destination restriction complete. Findings
Fix with agent prompt### Issue 1
apps/desktop/src/lib/trpc/routers/attachments/attachments.ts:12-18
`isWorkspaceAttachmentDestination` checks directory names, not where they point. If `.superset/attachments` is a symlink to another directory, this check passes and `copyFile` creates the attachment there. `COPYFILE_EXCL` prevents overwriting but does not prevent this redirection.
The composer checks the directory earlier, but this new main-process route does not enforce its own stated restriction. Check the real destination directory before copying and add a symlink test.
**How this was verified:** The route checks only path names before passing the unchanged destination to `copyFile`, which follows directory symlinks.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryLocal chat attachments with a disk path now use an Electron file copy instead of a base64 upload.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Chat attachment] --> B{Local workspace and disk path?}
B -->|Yes| C[Electron copy with COPYFILE_EXCL]
B -->|No| D[Check upload limits]
D --> E[Read and upload base64]
C --> F{Filename exists?}
E --> F
F -->|Yes| G[Try a numbered filename]
G --> B
F -->|No| H[Return relative attachment path]
Reviews (1) · Last reviewed commit: "fix(desktop): copy local chat attachment..." · Reviewed by Greptile |
| export function isWorkspaceAttachmentDestination(path: string): boolean { | ||
| const directory = dirname(path); | ||
| return ( | ||
| isAbsolute(path) && | ||
| basename(directory) === ATTACHMENTS_DIR_NAME && | ||
| basename(dirname(directory)) === ATTACHMENTS_PARENT_NAME | ||
| ); |
There was a problem hiding this comment.
Symlinks redirect attachment copies
isWorkspaceAttachmentDestination checks directory names, not where they point. If .superset/attachments is a symlink to another directory, this check passes and copyFile creates the attachment there. COPYFILE_EXCL prevents overwriting but does not prevent this redirection.
The composer checks the directory earlier, but this new main-process route does not enforce its own stated restriction. Check the real destination directory before copying and add a symlink test.
How this was verified: The route checks only path names before passing the unchanged destination to copyFile, which follows directory symlinks.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/lib/trpc/routers/attachments/attachments.ts
Line: 12-18
Comment:
**Symlinks redirect attachment copies**
`isWorkspaceAttachmentDestination` checks directory names, not where they point. If `.superset/attachments` is a symlink to another directory, this check passes and `copyFile` creates the attachment there. `COPYFILE_EXCL` prevents overwriting but does not prevent this redirection.
The composer checks the directory earlier, but this new main-process route does not enforce its own stated restriction. Check the real destination directory before copying and add a symlink test.
**How this was verified:** The route checks only path names before passing the unchanged destination to `copyFile`, which follows directory symlinks.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Resolve reap.ts/reap.test.ts against main's archive hook. Port the local copy onto sendAttachmentsToWorkspace: in a local workspace a file with a disk path is copied into the worktree by the main process and never goes to storage; everything else takes #8704's storage route.
|
Preview update published for development build |
…fileId on cloud copies Part of the attachments plan (PR 3: seams 8, 2, and the fileId carry-through of seam 3). The host's attachment store had no retention. Nothing deletes chat.db rows and a terminal launch has no session, so there is no session delete to hook. Instead, metadata.json records lastUsedAt. Upload and import set it, and every path that hands an attachment out sets it again: read, agents.run's attached files block, and the ACP resolver. A daily sweep (not in sandboxes) removes entries unused for ATTACHMENT_RETENTION_DAYS. An entry written before this change is stamped, not removed. The check and the rename that takes the entry out of the store run in the same tick, so a hand-out on this event loop cannot land between them. The slow delete runs async, off the loop. A box's cached copy now keeps the fileId it was imported from, in its metadata and in a small .by-file-id index, so the adapters (next PR) can find a cloud part's cached copy without a scan. The first prompt of a cloud launch spreads that metadata into its parts. Without fileId, the first attachments of a cloud session would be the one kind a reader without the box cannot render. MAX_INLINE_ATTACHMENT_BYTES moves to @superset/shared/attachment-limits with MAX_THUMBNAIL_BYTES and ATTACHMENT_RETENTION_DAYS. The host and the shared launch schema use MAX_ATTACHMENTS for their max(10).
…tachments Part of the attachments plan (PR 4, seam 4). The Claude SDK adapter rendered an attachment part as `[name]`, and the Codex adapter dropped it with a notice. Only ACP resolved it. This is why desktop chat still flattens attachments into path tags in the text. Now all three take one resolver from the host (chat-v3/resolveAttachment.ts). It branches on the identity the part carries. `fileId` is a cloud workspace's storage object: served from the box's cached copy, or imported now when the store is empty, as on a recreated box. `attachmentId` is the host store entry itself. Each hand-out stamps lastUsedAt for the sweep. Bytes are read only for images, since every adapter gives other files by path. - Claude: an image goes as a base64 image block in the SDK's content-array form. Any other file goes as a "# Attached files" line with its name and path, because store files are named by id. - Codex: an image goes as app-server's `localImage` by path. Any other file goes as the same text block. - An unreadable file is named to the agent, not dropped silently. - Resolution is chained per adapter, so prompt order holds. A text-only prompt with nothing queued is still pushed synchronously. The protocol's attachment part now needs `attachmentId` or `fileId` (it needed `attachmentId` before), so a client can send a cloud part by fileId alone. Clients send parts only to hosts at or above ATTACHMENT_PARTS_MIN_HOST_VERSION (1.41.0, the first release with this change). agents.run's attached files block uses the same attachedFilesBlock, so terminal launches also list files by name. A failed resolve reports to Sentry. The host has no PostHog client, so the plan's PostHog event is not sent from here.
… attachments An attachment-only message can carry an empty text part, and the Anthropic API rejects an empty text content block.
…floor Desktop and mobile both decide between attachment parts and path tags from a host's version. One function next to ATTACHMENT_PARTS_MIN_HOST_VERSION keeps the two clients on the same rule. It coerces the version, so a canary or a dev build of a release at or above the floor counts.
Part of the attachments plan (desktop PR: seams 1, 3, 5, 7). Since #8704, every desktop attachment went through our storage, including attachments for a workspace on a machine someone owns. Chat flattened them into <attachment path> tags because two of three adapters dropped parts. Mobile showed those tags as raw text, and desktop showed a mobile image as a name badge. Send (seam 1): sendAttachments picks the transfer from where the workspace lives. A box: createUpload, presigned PUT, attachFiles; the part carries only fileId, so it renders without the box. A host (local or relay-reached): base64 attachments.upload; the part carries only attachmentId, and the bytes never reach our servers. A host workspace refuses a file over MAX_INLINE_ATTACHMENT_BYTES, before anything is sent. Composer (seam 3): sends attachment parts when the host's adapters read them. A local host is this build. A remote host or box must report hostReadsAttachmentParts (ATTACHMENT_PARTS_MIN_HOST_VERSION). Below the floor it sends path tags, as before. An attachment-only message leaves out the empty text part. Render (seam 5): UserMessageRow renders image parts through useAttachmentSource. A cloud part resolves through attachment.resolveEach (batched per render) and storage; a host part through attachments.read. The row for a message just sent is primed with the File it attached, so it does a read of neither. Paths (seam 7): sendAttachmentsToWorkspace, which terminal paste and drop and the below-floor composer use, now writes base64 into the worktree for a host, as before #8704. A box keeps storage and materialize. The Files tab and design mode refuse a file over the inline cap before the write.
…pace lives The clipboard paragraph described #8704's routing, which sent every non-local host's paste through storage. A box still goes through storage; a relay-reached machine gets base64 filesystem.writeFile again.
…parts and path tags Part of the attachments plan (mobile PR). Mobile uploaded every attachment to our storage when it was attached, and then had the host import it. That also happened for a workspace on a machine someone owns, whose bytes should never reach our servers. Mobile also showed a desktop path tag as raw text. - A host workspace's draft no longer uploads at attach time. At send, chat attachments go to the host as base64 attachments.upload (the part names attachmentId). Terminal attachments are written into the worktree with create-only base64 filesystem.writeFile. Both refuse a file over MAX_INLINE_ATTACHMENT_BYTES. - A cloud chat part carries its fileId and skips importFromCloud when the box reads parts (hostReadsAttachmentParts). An older box still gets the copy it imports. - useAttachmentFile reads a fileId part from storage (resolveEach, then a download into the cache), so it shows without the box. A host part still reads from the host. - Path tags in a message show as file cards. parseAttachmentTags moved from desktop into @superset/chat/core so both clients parse them the same way. - A send that finds an attachment that never started uploading (its draft's home was unknown when it was attached) starts it.
The doc assumed deployed boxes never update their host-service. They do: a bundle release repins every live environment, every wake builds the claim from it, and superset-boot installs the pin when its hash differs. Only a box that never boots again keeps an old bundle. Features gate on the version a box reports, like a remote host.
- ATTACHMENT_PARTS_MIN_HOST_VERSION is 2.0.4. 2.0.0 to 2.0.3 shipped without the adapters that read attachment parts, so the old 1.41.0 floor let those hosts receive parts they would drop. - The Files tab caps a drop at MAX_INLINE_ATTACHMENT_BYTES only for a workspace on another machine. A local drop keeps no cap, as before. - The cloud workspace attachment inputs in packages/trpc and desktop's thumbnail limit come from @superset/shared/attachment-limits. The values are the same. - The clipboard paragraph in cloud-sandbox-mismatches covers the same-machine route. - Translations for the new messages, including the Ukrainian catalog that main added.
…ts-9064 # Conflicts: # packages/host-service/src/trpc/router/agents/agents.ts
…ser (SUPER-3442) Adding an attachment seeded an upload entry at 0% for every draft. Since #9064, a draft for a workspace on a machine someone owns starts no upload at attach time: its bytes go to the host at send. Nothing ever settled the seeded entry, so the composer drew a 0% ring and kept Send disabled ("Uploading") for any photo, on any network, at any size. Only beginUpload now creates an entry, and only for an attachment the draft holds. A host draft has no entries, so its tray shows no ring and sends. PostHog, mobile build 140, last 14 days: 312 of 387 attachments added were removed again (about 4% on builds 113 and 137), and every attachments_sent had home=cloud. No host-workspace attachment send succeeded.
…ser (SUPER-3442) (#9675) Adding an attachment seeded an upload entry at 0% for every draft. Since #9064, a draft for a workspace on a machine someone owns starts no upload at attach time: its bytes go to the host at send. Nothing ever settled the seeded entry, so the composer drew a 0% ring and kept Send disabled ("Uploading") for any photo, on any network, at any size. Only beginUpload now creates an entry, and only for an attachment the draft holds. A host draft has no entries, so its tray shows no ring and sends. PostHog, mobile build 140, last 14 days: 312 of 387 attachments added were removed again (about 4% on builds 113 and 137), and every attachments_sent had home=cloud. No host-workspace attachment send succeeded. Co-authored-by: Harshith Mullapudi <17528887+harshithmullapudi@users.noreply.github.com>
This PR now carries the whole attachments plan
Attachments: durable for cloud sessions, local for local ones (v18). The plan's separate PRs are folded in here and closed. The checklist is in the tracking page.
resolve+resolveEach, reap files with the box (seam 6)lastUsedAt, daily sweep, fileId index, fileId on first-prompt parts, limits in shared (seams 2, 3, 8)localImage, one resolver (cache or import byfileId), name+path block, parts floor (seam 4)fileId, host branch, cloud rendering, path tags as cardsagents.tsimports)Decisions made while folding in (please check)
MAX_INLINE_ATTACHMENT_BYTES(25 MB) becomes an attachment part, and a bigger local file goes throughattachments.writeIntoWorktreeas a path tag, so the 451 MB.dmgstill works. A relay-reached host refuses files over 25 MB, as the plan says.attachments.uploadfor parts, and base64filesystem.writeFileinto.paradev/attachmentsfor paths; no storage. Cloud → storage, thenfileIdparts ormaterializeIntoWorkspacefor paths.ATTACHMENT_PARTS_MIN_HOST_VERSION = "2.0.4". 2.0.0–2.0.3 shipped without the new adapters. If this PR doesn't ship in 2.0.4, raise it before release. A local host is this build, so it always gets parts.@superset/chat/core(shared by desktop and mobile) and keeps this PR'sname="…"and both.paradev/.supersetprefixes.Checks on 4444ea9
ae52b5f402without these commits:background-namingsession tests: "path traversal detected". They pass alone and depend on test order.health.checksandbox test.check:i18n: nothing missing in 17 locales (Ukrainian added). Biome is clean on the changed files.Not verified / not in this PR
resolvable.integration.tsis a manual DB test, not run in CI.What & why
Fixes SUPER-3014. Attaching a 451MB
.dmgin a local workspace failed with "files over 50MB can't be sent to a remote workspace".This PR includes #8704 (SUPER-2658, merged in as
913077170c). #8704 sends desktop attachments through storage (createUpload→ presigned PUT to R2 →attachFilesfor cloud →materializeIntoWorkspace), which fixes the cloud-box ingress race. As written, it also sent local workspaces' attachments through our storage, and it refused files over 200MB.On top of #8704:
useWorkspaceHostTargetsays the workspace is on this machine (localorlocal-starting), the new Electron main routeattachments.writeIntoWorktreewrites every file into.superset/attachments:COPYFILE_EXCL. There is no size cap, and the file never passes through renderer memory.wx. It is capped atMAX_ATTACHMENT_BYTES._Nsuffixes, so the route never overwrites a file."".ensureWorkspaceAttachmentsDirmoves to@superset/shared/workspace-attachments-dir, so the desktop and host-service share one.gitignorerule.cloud-workspace/reap.ts/reap.test.tskeep main's archive hook and fix(desktop,host-service): send attachments through storage, not host-service bodies #8704'sdetachAll+reapOrphanFiles.After this, the only client that still sends a host workspace's files through storage is mobile (on main as well). The phone is never the host.
Against the attachments plan
The attachments plan:
Attachment names and cards (
f745e33547)Problem: sent messages showed the sanitized disk name in a plain badge, e.g.
Superset-arm64__21__1.dmg.What changed:
<attachment>tag now has an optional, escapedname="…"with the name the user attached. It is written only when that name differs from the disk name.attachmentDisplayName: the message row, the image fallback, the gallery and the queued-prompt label. Tags written before this fall back to the disk name.@superset/chat-ui/AttachmentFileCardand shared withAttachmentPills.Compatibility: a desktop build without this change does not match a tag that has
name=, so it shows such a message's tag as raw text. That is cosmetic only, because the agent reads the tag text either way.Checked in the dev app:
Superset-arm64 (21).dmgandmeeting notes (final).txt. The cards read "Superset-arm64 (21)" / DMG and "meeting notes (final)" / TXT, with the full name on hover.Tests: desktop
bun test8872 pass. chat-ui tests andtscpass.check:i18nleaves the catalogs unchanged.Failed sends keep your files and say why (
30bf515d86)Problem: a failed chat send put the text back but dropped every attached file. A moved file showed a raw toast:
ENOENT: no such file or directory, stat '…'.What changed:
attachments.writeIntoWorktreenow returns{ ok: false, index, problem }when a source file ismissing, a folder (not-a-file) orunreadable. It checks readability by opening the file, because macOS privacy denials (EPERM) only show up atopen. It writes nothing in that case. A bad worktree and UNC paths still throw.sendAttachmentsToWorkspaceturns that result into anAttachmentSourceError.check:i18nreports nothing missing.Checked in the dev app:
keep me.txtandvanishing.txt, deleted the second from disk, then sent. The friendly toast appeared, and the text andkeep me.txtcame back. Pressing Enter again sent it with no toast and no storage requests.chmod 000file showed their messages.Tests: route tests for each problem (nothing written), and a
sendAttachmentsToWorkspacetest for the error's index, name and problem. Desktopbun test8874 pass.How I tested it
End to end in the dev app. This was the cloud sandbox's dev stack, with the desktop restarted with
RENDERER_REMOTE_DEBUG_PORTand driven over CDP.acp-chatflag on through the renderer's PostHog client, as a setup override.DOM.setFileInputFiles):Superset-arm64 (21).dmg, the file from the report;notes.txt;createUpload/attachFiles/materializeIntoWorkspace/ R2 requests..superset/attachmentsholdsSuperset-arm64__21_.dmgandnotes.txt, both byte-identical to the sources (cmp), plusimage.png(64×64 PNG) and.gitignore(*).git statusin the worktree is clean.Not checked in the app:
Automated:
bun test: 8871 pass, 0 fail. It covers the new route tests (order, never overwrite, refuse a directory or UNC source before writing) and the newsendAttachmentsToWorkspacecases (same-machine send never touches storage and keeps the order of path, blob, path; blob cap; path-count mismatch throws).packages/trpc(752 pass) and the host-service attachment + chat-v3 suites pass.tscpasses in desktop, host-service and shared. Biome,check:i18nandsherifare clean.Merge with main (
71b7e89028,ae52b5f402)71b7e89028merges main at9fca85d810.ae52b5f402merges7d6ec2de2f(#9265), with no conflicts, and formatsattachmentTags.ts.Conflicts and how they were resolved:
Composer.tsx: main's send path is kept (restoreDraft/prependToDraft, the hiddenchatContextpart, link chips). When a send fails, the composer restores the draft with only the attachments thatuseUploadAttachmentskeeps. The bad file is dropped, the other files stay, and theAttachmentSourceErrormessage shows.attachmentTags.test.ts: main'slegacyPastedMessagehelper and its.paradev+.supersetreader test are kept, together with this PR'sname=/attachmentDisplayNametest.attachmentTags.tsmerged cleanly: it reads both dirs and keeps the escapedname.uploadPastedFiles.ts(modify/delete): it stays deleted, and nothing imports it.TerminalPane.tsx: this PR'sAttachmentLimitErrorimport, plus main'sLinkActionMenu.AttachmentPills.tsx: main'sRevealButtonandgroup/pill, rendered with this PR's sharedAttachmentFileCard.chat-v3/agentImages.tsandtrpc/router/attachments/attachments.ts: these use the sharedensureWorkspaceAttachmentsDirinstead of main's localattachmentsDir.uk, so I wrote Ukrainian translations for those three strings..paradevchange:ensureWorkspaceAttachmentsDirnow writesWORKSPACE_ATTACHMENTS_GITIGNORE. The Electron routeattachments.writeIntoWorktreeand hostmaterializeIntoWorkspacealready build paths fromWORKSPACE_ATTACHMENTS_DIR, so they now write to.paradev/attachments. ThesendAttachmentsToWorkspacetest fixtures now use.paradev/attachments. Readers still accept.superset/attachments. A grep of this PR's diff against main finds no new.superset/attachments. The only"*\n"left is a test assertion on the.gitignorecontent, the same as main'sagentImages.test.ts.Checks run on
ae52b5f402:bun run typecheck: desktop, host-service, shared, trpc and chat-ui all pass.bun test:health.check … sandbox modeis environmental on a cloud box.pullRequests.mergePR > a failed refresh still reports the merge as donefailed once in the full run (called 2 times, expected 1). It passed 3 of 3 times on its own, and this PR does not change that directory.bunx biome checkon the changed files: clean.bun run check:i18n: 0 missing in all 17 locales.Not checked: I did not run the app after the merge. The new failed-send path through
restoreDraftis covered by typecheck only. No test drives it, and I did not use it in the app.Summary by CodeRabbit
New Features
Bug Fixes